using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public interface IInitializable
{
    void Initialize(object data);
}
public class SettingPanel : BasePanel, IInitializable
{
    public Toggle musicToggle;
    public Toggle soundToggle;
    public Toggle vibrationToggle;
    public void Initialize(object data)
    {
        Debug.Log("SettingPanel initialized" + data);
    }

    public void OnCloseClick()
    {
        // 关闭面板
        PanelManager.Instance.ClosePanel<SettingPanel>();
    }

    public override void OnOpen()
    {
        base.OnOpen(); // 调用基类的 OnOpen 方法

        // 在面板打开时执行的逻辑
        Debug.Log("SettingPanel opened");

        // 获取音乐开关状态
        bool isMusicOn = AudioManager.Instance.IsMusicOn;
        musicToggle.isOn = isMusicOn;

        // 获取音效开关状态
        bool isSoundEffectsOn = AudioManager.Instance.IsSoundEffectsOn;
        soundToggle.isOn = isSoundEffectsOn;

        //获取震动开关状态
        bool isVibrationOn = AudioManager.Instance.IsVibrationOn;
        vibrationToggle.isOn = isVibrationOn;
    }

    public override void OnClose()
    {
        base.OnClose(); // 调用基类的 OnClose 方法

        // 在面板关闭时执行的逻辑
        Debug.Log("SettingPanel closed");
    }

    public void OnPPClick()
    {
        Application.OpenURL("https://www.crazyfoodsorting.com/privacy-policy.html");
    }

    public void OnCUClick()
    {
        string recipient = "walkerbryant64@gmail.com";
        string subject = "Crazy Food-Goods Sorting";
        string body = "";
        string emailUrl = $"mailto:{recipient}?subject={UnityWebRequest.EscapeURL(subject)}&body={UnityWebRequest.EscapeURL(body)}";
        Application.OpenURL(emailUrl);
    }

    public void OnMusicClick()
    {
        // 切换音乐开关
        AudioManager.Instance.ToggleMusic();
    }

    public void OnSoundClick()
    {
        // 切换音效开关
        AudioManager.Instance.ToggleSoundEffects();
    }

    public void OnVibrationClick()
    {
        // 切换震动开关
        AudioManager.Instance.ToggleVibration();
    }
}
